<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :before-open="handleOpenBefore"
        :permission="permissionList"
      >
        <template slot="menuLeft">
          <el-upload
              class="upload-inline"
              action=""
              :show-file-list="false"
              accept=".xls"
              :http-request="handleImport"
            >
            <el-button type="primary" size="small">导入</el-button>
          </el-upload>        
        </template>
        <template slot="menuRight">
          <el-button
            @click="handleDownloadClick"
            type="text"
            size="small"
          >模板下载</el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import baseCrud from '@/mixins/base-crud'
import {stationCodeImport,templateStation} from '@/api/support/swparamstation'
import { handleExcelResponse } from "@/util/util";
export default {
  name: 'swparamstation',
  mixins: [baseCrud('support/swparamstation')],
  data() {
    return {}
  },
  computed: {
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.support_sw_param_station_add, false),
        delBtn: this.vaildData(this.permissions.support_sw_param_station_del, false),
        editBtn: this.vaildData(this.permissions.support_sw_param_station_edit, false)
      };
    }
  },
  methods: {
     handleImport(item) {
      this.$message.info("正在导入，请耐心等待！");
      let file = item.file;
      let param = new FormData();
      param.append("file", file);
      stationCodeImport(param).then(() => {
        this.$notify({
          title: "成功",
          message: "导入成功",
          type: "success",
          duration: 2000
        });
        this.getList(this.page);
      });
    },
    async handleDownloadClick () {//导出模板
      this.uploading = true;
      try {
        const res = await templateStation();
        handleExcelResponse(res);
      } finally {
        this.uploading = false;
      }
    },
    handleOpenBefore(done, type) {
                window.boxType = type;
                done();
            },
    },
  }
</script>
